package com.woniuxy01;

import java.util.Scanner;

public class Test02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入要查找的元素");
        int num=sc.nextInt();
        int[] a={1,2,3,4,5,6,7,8};
        int left=0,right=a.length-1;
        int middle=0;
        boolean flag=false;
        while(left<=right){
            middle=(left+right)/2;
            if(num>a[middle]){
                left=middle+1;
            }else if(num<a[middle]){
                right=middle-1;
            }else {
                flag=true;
                break;
            }
        }

        if(flag){
            System.out.println(middle);
        }else {
            System.out.println(-1);
        }

    }
}
